<!-- 我的按钮 -->

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import MyBtn from '@admin/components/choose/components/MyBtn'
import MySingle from '@admin/components/choose/ChooseUserOne/MySingle'

// ============================== 导出组件 ============================== //

export default CORE.extend(MyBtn, {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyBtn',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb(), CORE.mixInfo(), CORE.mixTree('organ', 'organ_')],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    ...MyBtn.computed,
    ...MySingle.computed,
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    ...MyBtn.methods,

    /**
     * 转换选中项
     */
    transChosen(chosen) {
      const { param, organIdList } = this

      if (param.treeId) {
        chosen.forEach((item) => {
          item.organId = [param.treeId]
        })
      } else {
        chosen.forEach((item) => {
          item.organId = organIdList.filter((id) => (item.organId || []).includes(id))
        })
      }

      return chosen
    },
  },
})
</script>
